﻿using System.Reflection;

namespace System.Xml.Linq
{
	internal static class XAttributeEnumExtensions
	{
		 		/// <summary>
		/// Gets the value of the attribute as the requested enumeration type.
		/// </summary>
		/// <typeparam name="T">The type of attribute as enum</typeparam>
		/// <param name="attribute">The attribute.</param>
		/// <returns>Attribute as enum of type T</returns>
		public static T AsEnum<T>(this XAttribute attribute)
		{
			EnumReflector.EnsureIsEnum(typeof(T));
			return EnumReflector.Parse<T>(attribute.Value);
		}

	}
}